﻿using AuthenticationCenter.Service;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AuthenticationCenter.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class AuthenticationController : Controller
    {
        private readonly IJwtService _jwtService;
        public AuthenticationController(IJwtService jwtService)
        {
            _jwtService = jwtService;
        }

        [Route("Login")]
        public string Login(string name, string password)
        {
            if ("page".Equals(name) && "123456".Equals(password))
            {
                // token
                var token = _jwtService.GetToken(name, password);
                return JsonConvert.SerializeObject(new
                {
                    isSuccess = true,
                    token,
                });
            }
            else
            {
                return JsonConvert.SerializeObject(new
                {
                    isSuccess = false,
                    message = "name or password invalide",
                });
            }
        }

        public IActionResult Index()
        {
            return View();
        }
    }
}
